<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var scorePoolDataGrid;
    $(function() {
        scorePoolDataGrid = $('#scorePoolDataGrid').datagrid({
            url : '${path }/scorePool/dataGrid',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'id',
            sortOrder : 'asc',
            pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
            frozenColumns : [ [ {
                title : 'id',
                field : 'id',
                width : 40,
                hidden : true
            } ] ],
            columns : [ [ {
                field : 'score',
                title : '奖金池总数',
                width : 150
            },{
                field : 'sumScore',
                title : '增值点',
                width : 150
            },{
                field : 'publishTime',
                title : '上次释放时间',
                width : 200
            } ,{
                field : 'action',
                title : '操作',
                width : 130,
                formatter : function(value, row, index) {
                    var str = '';
                    str += $.formatString('<a href="javascript:void(0)" class="scorePool-easyui-linkbutton-edit" ' +
                        'data-options="plain:true,iconCls:\'fi-pencil icon-blue\'"' +
                        ' onclick="avgScorePool(\'{0}\');" >按增值点总数派发</a>', row.id);
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.scorePool-easyui-linkbutton-edit').linkbutton({text:'按增值点总数派发'});
            }
            ,toolbar : '#scorePoolToolbar'
        });
    });


    function avgScorePool(){
        parent.$.messager.confirm('询问', '您是否要按增值点总数派发?', function(b) {
            if (b) {
                progressLoad();
                var awards =  prompt("请输入你要派发的金额:","")
                while(!awards){
                    awards =  prompt("请输入金额:","")
                }
                $.post('${path }/scorePool/insertAvgScore?awards=' + awards, {

                }, function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        scorePoolDataGrid.datagrid('reload');
                    }else{
                        parent.$.messager.alert('提示', result.msg, 'info');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }

    function  lockIncrement() {
        progressLoad();
        $.post('${path }/scorePool/lockIncrement', {

        }, function(result) {
            if (result.success) {
                parent.$.messager.alert('提示', result.msg, 'info');
                scorePoolDataGrid.datagrid('reload');
            }else{
                parent.$.messager.alert('提示', result.msg, 'info');
            }
            progressClose();
        }, 'JSON');
    }

    function unlockIncrement(){
        progressLoad();
        $.post('${path }/scorePool/unlockIncrement', {

        }, function(result) {
            if (result.success) {
                parent.$.messager.alert('提示', result.msg, 'info');
                scorePoolDataGrid.datagrid('reload');
            }else{
                parent.$.messager.alert('提示', result.msg, 'info');
            }
            progressClose();
        }, 'JSON');
    }
    
    
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',fit:true,border:false">
        <table id="scorePoolDataGrid" data-options="fit:true,border:false"></table>
    </div>
    <div id="scorePoolToolbar" >
            <a onclick="lockIncrement();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-lock icon-green'">锁定</a>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <a onclick="unlockIncrement();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-unlock icon-green'">解锁</a>
    </div>
</div>
